(function() {
'use strict';

angular
	.module('votingBackend')
	.controller('ApplicationController', ['$scope', 'USER_ROLES', 'AuthService', '$cookies', '$timeout', '$state', ApplicationController]);

/** @ngInject */
function ApplicationController($scope, USER_ROLES, AuthService, $cookies, $timeout, $state) {
	console.log($cookies);
		$scope.currentUser = null;
		$scope.userRoles = USER_ROLES;
		$scope.isAuthorized = AuthService.isAuthorized;
		//console.log($cookies.get('userToken'))

		$scope.setCurrentUser = function (user) {
			$scope.currentUser = user;
			$cookies.put('userToken', $scope.currentUser);
		};

		$scope.logout = function () {
			AuthService.logout();
			$scope.currentUser = null;
			$cookies.remove('userToken');
		};

		if (!!$cookies.get('userToken')) {
			$scope.setCurrentUser($cookies.get('userToken'))
			console.log('user is currently logged in')
		}
		else {
			console.log('no user currently logged in')
		}

	}

})();